package org.xiangsai.core;

import io.grpc.Server;
import io.grpc.ServerBuilder;

import java.io.IOException;

public class ServerDemo {
    private Server server;

    public static void main(String[] args) {
        ServerDemo serverDemo=new ServerDemo();
        try {
            serverDemo.start();
            serverDemo.blockUntilShutdown();
        }
        catch (Exception ex)
        {
            System.out.println("服务端错误");
        }
        System.out.println("服务端退出");

    }

    private void start() throws IOException {
        int port = 50001;
        System.out.println("等待监听");
        server=ServerBuilder.forPort(port).addService(new HelloImpl()).build().start();
    }

    private void blockUntilShutdown() throws InterruptedException{
        if(server!=null){
            server.awaitTermination();
        }
    }
}
